<?php
$host = $argv[1] ?? '';
$path = $argv[2] ?? '';
$destPath = $argv[3] ?? '';

if (empty($host)) die("HOST 不能为空");
if (empty($path)) die("原始路径 不能为空");
if (empty($destPath)) die("目标路径 不能为空");

while (true) {
    $cmd = "rsync -avz --delete  -e \"ssh  -o PubkeyAuthentication=yes   -o stricthostkeychecking=no\"  root@{$host}:{$path}  {$destPath}";
    exec($cmd);
    $time = rand(40, 70);
    echo "同步文件夹 root@{$host}:{$path}  {$destPath} 执行完成,即将休眠 {$time} 秒.... \n";
    sleep($time);
}